package reflect.test.test3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @version 1.0
 * @author:罗苏琴
 * @Date 2024/12/3 上午10:57
 */
public class GetAccessStudentMethod {
    public static void main(String[] args) {
        Class clz= Student.class;
        try {
            Object student=clz.newInstance();
            Method setAddress=clz.getDeclaredMethod("setAddress", String.class);
            setAddress.setAccessible(true);
            setAddress.invoke(student,"郴江路29号");
            Object returnAddress =clz.getDeclaredMethod("getAddress").invoke(student);
            System.out.println("地址："+returnAddress);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}


